import request from '@/utils/request'

// 存储用户信息
export function setUserInfo(openid, headImg, memberName) {
  return request({
    url: 'user/login',
    method: 'POST',
    data: {
      openid,
      headImg,
      memberName
    }
  })
}

// 获取用户信息
export function getUserInfo(openid) {
  return request({
    url: 'user/info',
    method: 'POST',
    data: {
      openid
    }
  })
}

// 更新用户信息
export function update(data) {
  return request({
    url: 'user/update',
    method: 'POST',
    data
  })
}

export function getPhone(code, iv, encryptedData) {
  return request({
    url: 'user/getPhone',
    method: 'POST',
    data: {
      code,
      iv,
      encryptedData
    },
    header: {
      'content-type': 'application/json'
    }
  })
}

export function getOpenId(code) {
  return request({
    url: 'user/get_openid',
    method: 'POST',
    data: {
      code
    }
  })
}

// 根据userId查询拥有优惠券
export function getCodeStatus(userId, status, page, size) {
  return request({
    url: 'user/queryByCodeStatus',
    method: 'POST',
    data: {
      userId,
      status,
      page,
      size
    }
  })
}

// 个人订单记录
export function getOrder(openId, page, size) {
  return request({
    url: 'user/order',
    method: 'POST',
    data: {
      openId,
      page,
      size
    }
  })
}

// 激活会员卡
export function activationCard(cardId, userId, password) {
  return request({
    url: 'memberShipCard/active',
    method: 'POST',
    data: {
      cardId,
      userId,
      password
    }
  })
}

// 小程序获取优惠券接口（会员信息端）（线下买单用）
export function getCodeHasMember(userId, amount, totoOrKele, storeId) {
  return request({
    url: 'memberShipCard/getCode',
    method: 'POST',
    data: {
      userId,
      amount,
      totoOrKele,
      storeId
    }
  })
}

// 支付宝小程序用户登入/注册接口
export function loginByAli(phone, zfbId, headImg2, memberName2) {
  return request({
    url: 'alipay/login',
    method: 'POST',
    data: {
      phone,
      zfbId,
      headImg2,
      memberName2
    }
  })
}

export function getPhoneByAli(data) {
  return request({
    url: 'alipay/getPhone',
    method: 'POST',
    data
  })
}

export function getAliUserInfo(authCode) {
  return request({
    url: 'alipay/getUserInfo',
    method: 'POST',
    data: {
      authCode
    }
  })
}

export function updateAliUser(data) {
  return request({
    url: 'alipay/updateUser',
    method: 'POST',
    data
  })
}
